﻿using Microsoft.AspNetCore.Hosting;

namespace ZhongKeSite.FileResources
{
    public class PathProvider : IPathProvider
    {
        private IHostingEnvironment _hostingEnvironment;

        public PathProvider(IHostingEnvironment environment)
        {
            _hostingEnvironment = environment;
        }

        /// <summary>
        /// 为保证linux和window通用性,path路径分隔符,请使用/号
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public string MapPath(string path)
        {
            //var filePath = string.Concat(_hostingEnvironment.ContentRootPath, path.Replace("/",@"\"));//照成linux环境下不兼容
            var filePath = string.Concat(_hostingEnvironment.ContentRootPath, path);
            return filePath;
        }
    }
}
